$(function () {
    "true" === $.cookie("zrotcUser") && ($("#weuiAgree").prop("checked", !0),
        $("#phoneNum").val($.base64.decode($.base64.decode($.cookie("_zum")))),
        $("#password").val($.base64.decode($.base64.decode($.cookie("_pmt")))));
    var e = "",
        o = function () {
            var o = new XMLHttpRequest;
            o.responseType = "blob",
                o.open("GET", hostUrl + "/user/captcha.png?time=" + (new Date).getMilliseconds(), !0),
                o.onload = function (o) {
                    $("#captchaImg").attr("src", window.URL.createObjectURL(this.response));
                    var pragma = this.getResponseHeader("pragma");
                    if (pragma) {
                        e = pragma.split(",")[1]
                    }

                },
                o.send()
        };
    o(),
        $("#captchaImg").on("click", o),
        $("#loginBtn").on("click",
            function () {
                var s = $("#phoneNum").val(),
                    a = $("#password").val(),
                    c = $("#captcha").val();
                if (s && /1[3|4|5|7|8]\d{9}/.test(s))
                    if (a) {
                        if (c && /.{5}/.test(c)) {
                            $.ajax({
                                method: "post",
                                url: hostUrl + "/customer/login",
                                contentType: "application/json; charset=utf-8",
                                data: JSON.stringify({
                                    mobile: s,
                                    password: a,
                                    imgCode: c
                                }),
                                success: function (e) {
                                    if (!0 !== e.meta.success) $.toptip(e.meta.message, "error"),
                                        $("#captcha").val(""),
                                        o();
                                    else {
                                        t();
                                        e.data = {
                                            uid: 4,
                                            user_name: "杨欢",
                                            token: "1231231"
                                        }
                                        var s = e.data.uid;

                                        uid = s,
                                            sessionStorage.setItem("uid", s),
                                            sessionStorage.setItem("user", e.data.user_name),
                                            sessionStorage.setItem("token", e.data.token),
                                            location.hash = "trade"
                                    }
                                }
                            });
                        } else {
                            $.toptip("请输入五位验证码")
                        }
                    }
                    else $.toptip("请输入密码");
                else $.toptip("请输入11位手机号")
            });
    var t = function () {
        if ($("#weuiAgree").prop("checked")) {
            var e = $("#phoneNum").val(),
                o = $("#password").val();
            $.cookie("zrotcUser", "true", {
                expires: 7
            }),
                $.cookie("_zum", $.base64.encode($.base64.encode(e)), {
                    expires: 7
                }),
                $.cookie("_pmt", $.base64.encode($.base64.encode(o)), {
                    expires: 7
                })
        } else $.cookie("zrotcUser", "false", {
            expire: -1
        }),
            $.cookie("_zum", "", {
                expires: -1
            }),
            $.cookie("_pmt", "", {
                expires: -1
            })
    }
});